/*
	主页加载方法
	@eric
*/
//系统时间显示
setInterval("document.getElementById('nowTime').innerHTML=new Date().toLocaleString()+' 星期'+'日一二三四五六'.charAt(new Date().getDay());",1000);
var setting = {
	data: {
		simpleData: {
			enable: true
		}
	},
	view: {
		selectedMulti: false,
		showLine : false,
		dblClickExpand: false,
		showIcon: true,
	},
	callback: {
		onClick:function(e, id, node){
			var zTree = $.fn.zTree.getZTreeObj("menuTree");
			if(node.isParent) {
				zTree.expandNode(node);
			} else {
				addTabs(node.name, node.file);
			}
		}
	}
};

$(function() {
	$.ajax({
		url :'menuTree',
		type:'get',
		dataType:'text',
		success:function(data){
			$.fn.zTree.init($("#menuTree"), setting, $.parseJSON(data));
		}
	});

	var zTree = $.fn.zTree.getZTreeObj("menuTree");
	

	//中间部分tab
	$('#tabs').tabs({
		border:false,
		fit:true,
		onSelect: function(title, index){
			var treeNode = zTree.getNodeByParam("name", title, null);
			zTree.selectNode(treeNode);
		}
	});

	$('.index_panel').panel({  
	  width:300,  
	  height:200,  
	  closable:true,
	  minimizable:true,
	  title: 'My Panel'
	});
	
});

//添加一个选项卡面板 
function addTabs(title, url, icon){
	if(!$('#tabs').tabs('exists', title)){
		$('#tabs').tabs('add',{  
			title:title,  
			content:'<iframe src="'+url+'" frameBorder="0" border="0" scrolling="yes" style="width: 100%; height: 100%;"/>',  
			closable:true
		});
	} else {
		$('#tabs').tabs('select', title);
		var currentTab = $('#tabs').tabs('getTab',title);
		var url = $(currentTab.panel('options').content).attr('src');
		$('#tabs').tabs('update',{
			tab:currentTab,
			options:{
				title: title,
				href: url
			}
		});
	}
}